const fs = require('fs')
let f32 = new Float32Array(4)
f32[0]=1;
f32[1]=2;
f32[2]=3;
f32[3]=4
fs.writeFileSync('testarray', new Buffer(f32.buffer));
let ret = fs.readFileSync('testarray')
let ab = toArrayBuffer(ret)

console.log(ab, ret.length)
let f32_1 = new Float32Array(ab)

console.log(f32_1)
console.log(JSON.stringify(f32))
function toArrayBuffer(buf) {
    var ab = new ArrayBuffer(buf.length);
    var view = new Uint8Array(ab);
    for (var i = 0; i < buf.length; ++i) {
        view[i] = buf[i];
    }
    return ab;
}
function toBuffer(ab) {
    var buf = new Buffer(ab.byteLength);
    var view = new Uint8Array(ab);
    for (var i = 0; i < buf.length; ++i) {
        buf[i] = view[i];
    }
    return buf;
}
